function promiseAjax(obj){
    return new Promise(function(resolve, reject){
        if(obj.url === undefined){
            throw new Error("地址必填")
        }
        if({}.toString.call(obj.url) !== '[object String]'){
            throw new Error("地址非法")
        }
        if(obj.method === undefined){
            obj.method = 'get'
        }
        if(obj.method.toLowerCase() !== 'get' && obj.method.toLowerCase() !== 'post'){
            throw new Error("请求方式必须是get或post")
        }
        if(obj.async === undefined){
            obj.async = true
        }
        if({}.toString.call(obj.async) !== '[object Boolean]'){
            throw new Error("async必须是布尔值")
        }
        if(obj.dataType === undefined){
            obj.dataType = 'json'
        }
        if(obj.dataType !== 'json' && obj.dataType !== 'text'){
            throw new Error("dataType必须是json或text")
        }
        if(obj.data){
            if({}.toString.call(obj.data) === '[object String]'){
                var str = obj.data
            }else if({}.toString.call(obj.data) === '[object Object]'){
                var str = ''
                for(var attr in obj.data){
                    str += '&' + attr + '=' + obj.data[attr]
                    str.slice(1)
                }
            }else{
                throw new Error("data必须的键值对")
            }
            if(obj.method.toLowerCase() === 'get'){
                obj.url += '?' + str
            }
        }
        var xhr = new XMLHttpRequest()
        xhr.onreadystatechange = function(){
            if(xhr.readyState === 4){
                if(xhr.status>=200 && xhr.status<300){
                    var res = xhr.responseText;
                    if(obj.dataType === 'json'){
                        res = JSON.parse(res)
                    }
                    resolve(res)
                }else{
                    reject()
                }
            }
        }
        xhr.open(obj.method,obj.url,obj.async)
        if(obj.data && obj.method.toLowerCase() === 'post'){
            for(var attr in obj.headers){
                xhr.setRequestHeader(attr,obj.headers[attr])
            }
            xhr.send(str)
            return;
        }
        xhr.send()
    })
}